// components/item-card/item-card.js
import formatTime from '../../utils/formatTime.js'
import Dialog from '../../miniprogram_npm/@vant/weapp/dialog/dialog';
var req = require("../../utils/action.js");
var utils = require("../../utils/util.js");
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    mine: Boolean,
    item: Object,
    anonymousList: Array
  },
  options: {
    
  },
  observers: {
    ['item.nickName'](val) {
      if (val) {
        console.log(val)
        let _nickName = this.properties.item.ifAnonymous?'匿名用户':this.properties.item.nickName
        this.setData({_nickName})
      }
    },
    ['item.createTime'](val) {
      if (val) {
        //console.log(val)
        this.setData({
          _createTime: formatTime(new Date(val))
        })
      }
    },
  },

  /**
   * 组件的初始数据
   */
  data: {
    _createTime: '',
    _nickName: ''
  },

  /**
   * 组件的方法列表
   */
  methods: {
    previewImage(e){
      console.log(e)
      wx.previewImage({
        urls: [e.target.dataset.imgurl],
      })
    },
    callComment(){
      this.triggerEvent('callComment',{commentId:this.data.item.id,nickName:this.data.item.randomNickName || this.data.item.nickName,toCustomerId:this.data.item.customerId});
    },
    deleteComment(){
      let that = this
      console.log("deleteCommentdeleteCommentdeleteCommentdeleteComment")
      Dialog.confirm({
        title: '确认要删除此评论吗',
      }).then(() => {
        console.log("that.data.item.id:"+that.data.item.id)
        let _url = req.actions.ym+ "invitation/deleteComment",data={commentId:that.data.item.id}
        console.log(_url)
        utils.myResquest(data,_url,function(res){
          console.log("onLongPressComment===>"+JSON.stringify(res))
          that.triggerEvent('refreshCommentList',{})
          //that.getCommentList()
          wx.showToast({
            title: '已删除~',
            icon: 'none'
          })
        })
      }).catch((err)=>{})
    } 
  }
})

